<?php

include_once('ResultObject.php');

class Publication extends ResultObject
{
    function Publication() {
        $this->resultType = "Publication";
    }
    
    
    public function getPublicationCount() 
    {
        return $this->json->d->Publication->TotalItem;
    }
   
    public function getCitations($idx) 
    {
       if ($this->json != "0") {
        return $this->json->d->Publication->Result[$idx]->CitationCount;
       }
       else {
           return -1;
       }
    }
    
    public function getPapers() {
        $papers = array();
      
        /*foreach ($this->json->d->Publication->Result as $paper) 
        {
        
            array_push($papers, $paper);
        }*/
     
        return $this->json->d->Publication->Result;
    }
    
      public function getRequest()
    {
   
        $query = $this->masUrl . $this->appID . "&ResultObjects=Publication";
        
        if (!is_null($this->domainID)) 
        {
            $query .= "&DomainID=" . $this->domainID;
        }
        
          if (!is_null($this->subDomainID)) 
        {
            $query .= "&SubDomainID=" . $this->subDomainID;
        }
        
          if (!is_null($this->orgID)) 
        {
            $query .= "&OrganizationID=" . $this->orgID;
        }
        
          if (!is_null($this->searchText)) 
        {
            $query .= "&FullTextQuery=" . $this->searchText;
        }
        
        if (!is_null($this->yearStart)) 
        {
            $query .= "&YearStart=" . $this->yearStart;
        }
          
        if (!is_null($this->yearEnd)) 
        {
            $query .= "&YearEnd=" . $this->yearEnd;
        }
        
          if (!is_null($this->startIdx)) 
        {
            $query .= "&StartIdx=" . $this->startIdx;
        }
        else {
             $query .= "&StartIdx=1";
        }
        
          if (!is_null($this->endIdx)) 
        {
            $query .= "&EndIdx=" . $this->endIdx;
        }
        else {
            $query .= "&EndIdx=1";
                     }
       
        return $query;

    
    }
    
    function getPaperObj () {
        $papers = array();
      
        foreach ($this->json->d->Publication->Result as $paper) 
        {
            $paperObj = new paperObj;
            $paperObj->urlArray = $paper->FullVersionURL;
            $paperObj->id = $paper->ID;
            $paperObj->title = $paper->Title;
            $paperObj->arnumber = 0;  
            array_push($papers, $paperObj);
        }
        return $papers;
    }
 
  
}

    class PaperObj
    {
        public $urlArray, $id, $title, $arnumber, $textFound; 
    }
    
?>